﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>限制排产批次选择</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
   
</head>
<body>
    <div class="panelSection">    
        <div class="easyui-panel " title="搜索区域" style="padding:3px;width: 100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
               <div style="margin: 3px 0px 3px 3px">
                    <div style="float: left">
                        <div class="divLabel" style="margin-bottom: 5px; ">
                            订单号：</div>
                        <input id="txtMfgorderName" class="easyui-textbox" name="ProductNo" type="text"
                            data-options="" style="width: 120px; height: 22px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            件号：</div>
                        <input id="txtProduct" class="easyui-textbox" name="ProductNo" type="text" data-options=""
                            style="width: 120px; height: 22px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            批次号：</div>
                        <input id="txtContainer" class="easyui-textbox" name="ProductNo" type="text" data-options=""
                            style="width: 120px; height: 22px" />
                    </div>
                     <div style="float: left; margin-left: 20px">
                        <a href="#" id="btnSearch" class="easyui-linkbutton" data-options="" style="margin-top: 16px;">
                            查询</a>
                    </div>
                    <div style="float: left; margin-left: 20px">
                        <a href="#" id="btnReset" class="easyui-linkbutton" data-options="" style="margin-top: 16px;">
                            重置</a>
                    </div>
                    <div style="clear: both"></div> 
               </div>

        </div> 

    </div> 
     <div class="panelSection">    
        <div class="easyui-panel " title="结果区域" style="padding:3px;width: 100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <div style="margin: 3px 0px 3px 3px">
                <table id="gdContainerInfo" class="easyui-datagrid" style="width: 100%; height: 350px"
                        data-options="rownumbers:true,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:false,pageNumber:1,pageSize:5,pageList:[5,10,20]">
                    </table>
                    <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            group:'paging-tail-btns',
                            id:'pageGo'
                    }]
                ">
                    </div>
            </div>
        </div>
    </div>

</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：Wangjh
    日期：2022-04-28
    描述：有限排产js
    */
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        parentID: null,
        editIndex: null, //easyUI单元格编辑
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsLMWorkTimeHandler.ashx",
        //初始化页面
        init: function () {
            page.parentID = getParam("parentDiv");
            //var containers = parent.$("#" + page.parentID).dialog('options').poPupData;
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
            page.addEditCell();

        },
        addEditCell: function () //给easyuigrid新增editcell方法
        {
            $.extend($.fn.datagrid.methods, {
                editCell: function (jq, param) {
                    return jq.each(function () {
                        var opts = $(this).datagrid('options');
                        var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor1 = col.editor;
                            if (fields[i] != param.field) {
                                col.editor = null;
                            }
                        }
                        $(this).datagrid('beginEdit', param.index);
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor = col.editor1;
                        }
                    });
                }
            });
        },
        endEditing: function (gridId) {
            if (page.editIndex == undefined) { return true }
            if ($('#' + gridId).datagrid('validateRow', page.editIndex)) {
                $('#' + gridId).datagrid('endEdit', page.editIndex);
                page.editIndex = undefined;
                return true;
            } else {
                return false;
            }
        },

        //页面事件绑定
        bind: function () {
            //批次列表
            $("#gdContainerInfo").datagrid({
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                onCheck: function (index, rowData) { },
                onUncheck: function (index, rowData) { },
                onCheckAll: function (index, rowData) { },
                onUncheckAll: function (index, rowData) { },
                onClickCell: function (index, field) {
                    //编辑单元格
                    if (page.endEditing('gdContainerInfo')) {
                        $('#gdContainerInfo').datagrid('editCell', { index: index, field: field });
                        page.editIndex = index;
                    }
                },
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'MFGORDERNAME', title: '订单号', width: 120 },
		         { field: 'CONTAINERNAME', title: '批次', width: 150 },
		         { field: 'PRODUCTDESC', title: '零件名称', width: 130 },
                 { field: 'QTY', title: '在制数', width: 60 },
                 { field: 'WORKFLOWINFO', title: '工艺信息', width: 180 },
                 { field: 'WORKFLOWSTEPNAME', title: '当前工序', width: 180 },
                 { field: 'CONTAINERTYPENAME', title: '流水卡类型', width: 100 },
                 { field: 'MATERIALDATE', title: '到料确认日期', width: 100, formatter: function (value, row, index) {
                     if (value != null) {
                         //value = value.replace("/", "-");
                         return dayjs(value).format("YYYY-MM-DD");
                     }
                 }
                 },
                 { field: 'EXPECTMATERIALDATE', title: '预计到料或齐套日期', width: 130, editor: { type: 'datebox' }, formatter: function (value, row, index) {
                     if (value != null) {
                         //value = value.replace("/", "-");
                         return dayjs(value).format("YYYY-MM-DD");
                     }
                 }
                 },
                 { field: 'MFGSTARTDATE', title: '订单开始日期', width: 100 },
                 { field: 'MFGENDDDATE', title: '订单结束日期', width: 100 },
		         { field: 'CONTAINERID', title: 'CONTAINERID', hidden: true },
		         { field: 'WORKFLOWID', title: '工艺', hidden: true },
                 { field: 'TOGETHERFLAG', title: '批次顺序', hidden: true },
                 { field: 'CONTAINERID', title: 'CONTAINERID', hidden: true },
                 { field: 'CONTAINERTYPE', title: '流水卡类型', hidden: true },
                 { field: 'PRODUCTID', title: '零件图号ID', hidden: true },
                 { field: 'PRODUCTNAME', title: '零件图号', hidden: true },
                 { field: 'PRODUCTREVISION', title: 'PRODUCTREVISION', hidden: true },
                 { field: 'WORKFLOWNAME', title: 'WORKFLOWNAME', hidden: true },
                 { field: 'WORKFLOWREVISION', title: 'WORKFLOWREVISION', hidden: true }

	           ]]
            });
            //查询按钮
            $('#btnSearch').on("click", function () {
                page.pageNumber = 1;
                page.searchData();
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.searchData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.searchData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.reset(true, true);
                page.pageNumber = 1; page.pagetotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });            

        },
        //查询
        searchData: function () {
            page.reset(false, true);
            var gridID = "#gdContainerInfo";
            var param = {
                action: "getApsSelectContainer",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber,
                containerName: $("#txtContainer").textbox('getValue'),
                mfgorderName: $("#txtMfgorderName").textbox('getValue'),
                productName: $("#txtProduct").textbox('getValue')
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $(gridID).datagrid('loading');
                    $(this).attr("disabled", "disabled"); //禁用按钮
                },
                success: function (data) {
                    //console.log(data);
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    var result = JSON.parse(data);
                    if (result.Result) {
                        //给分页对象赋值
                        page.pagetotal = result.RowCount;
                        $(gridID).datagrid('loadData', { total: result.RowCount, rows: result.DBTable });
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    alert(XMLHttpRequest.responseText);
                }
            });
        },        
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
            if (iscondition) {
                $('#txtMfgorderName').textbox('clear');
                $('#txtProduct').textbox('clear');
                $('#txtContainer').textbox('clear');
            }
            if (isresult) {
                clearEasyuiDataGrid("gdContainerInfo", 1);
            }
        }
    }
    $(function () {
        page.init();
    });
</script>
